What exception handling can enhance the robustness of this Python code snippet